<?php
namespace juven\libs {
    \defined( '_JEXEC' ) or die( 'Restricted access' );
    
    class View extends DynamicContainer{
        const EVENT_onError_ViewFileNotFoundOrNotReadable = "event_onError_ViewFileNotFoundOrNotReadable";
        
        public function __construct(array $container=array()){ parent::__construct($container); }

        public function render($controllerName, $actionName="index", $include_HeaderAndFooter = \TRUE){
            $viewFile = juven::config()->viewsFolderPath.$controllerName.\DIRECTORY_SEPARATOR.$actionName.'.php';
            if (!\is_readable($viewFile)){
                juven::eventsManager()->publish(self::EVENT_onError_ViewFileNotFoundOrNotReadable, $viewFile);
                juven::router()->loadPageNotFoundController();
                return \FALSE;
            }
            
            if ($include_HeaderAndFooter === \TRUE){ 
                require juven::config()->viewsFolderPath.'header.php';
                require $viewFile;
                require juven::config()->viewsFolderPath.'footer.php';
            } else {
                require $viewFile;
            }
        }
        
        public function __destruct(){ parent::__destruct(); }
    }
}
?>